# class DataTest:
#     def __init__(self, id, address):
#         self.id = id
#         self.address = address
#         self.d = {self.id: 1,
#                   self.address: "192.168.1.1"
#                   }
#
#     def __getitem__(self, key):
#         return "hello"

class Teacher:

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __getitem__(self, item):
        if item == "name":
            return self.name
        elif item == "age":
            return self.age
        else:
            raise Exception("没有key")

    def __setitem__(self, key, value):
        print(key)
        print(value)
        self.__setattr__(key, value)  # 正确的赋值姿态

        # self[key] = value

    def __del__(self):
        print('走了这个方法')

    def __delitem__(self, key):
        print(key)
        print('----------')
        del key


t1 = Teacher(name="kkx", age=31)
# print(t1.name)
t1['age'] = 50
print(t1['age'])

del t1['age']
print(t1['age'])

# print('res', res)

# print(abs(t1))
#  在对象的某些操作中, 会调用对象的 某些特定  魔术方法,
#  而恰巧魔术方法 可以改变某些结果
